﻿using System;
using System.Collections.Generic;
using System.Text;
using LockCrypt.Core;
using NUnit.Framework;

namespace LockCrypt.Tests.Core {
    [TestFixture]
    public class WildcardURLTests {
        [TestCase("http://www.google.com/", Result = true)]
        [TestCase("http://google.com/", Result = false)]
        [TestCase("http://www.google.co.za/", Result = false)]
        public bool NoWildcard(string wildcardUrl) {
            WildcardUrl urlInAccount = new WildcardUrl("http://www.google.com/");
            return urlInAccount.Matches(wildcardUrl);
        }

        [TestCase("http://www.google.com/", Result = true)]
        [TestCase("http://groups.google.com/", Result = true)]
        [TestCase("http://groups.google.com/group1", Result = true)]
        [TestCase("http://google.jp/", Result = false)]
        [TestCase("http://groups.google.jp/", Result = false)]
        public bool PartialDomainWildcard(string wildcardUrl) {
            WildcardUrl urlInAccount = new WildcardUrl("http://*.google.com/");
            return urlInAccount.Matches(wildcardUrl);
        }

        [TestCase("gopher://mycompany/login/", Result = true)]
        [TestCase("http://mycompany/search.aspx", Result = true)]
        [TestCase("http://google.com/", Result = false)]
        [TestCase("http://ftp.microsoft.com/", Result = false)]
        public bool ProtocolWildcard(string wildcardUrl) {
            WildcardUrl urlInAccount = new WildcardUrl("*://mycompany/");
            return urlInAccount.Matches(wildcardUrl);
        }

        [TestCase("ftp://ftp.yahoo.com", Result = true)]
        [TestCase("http://www.microsoft.com/", Result = true)]
        [TestCase("http://google.com/", Result = false)]// correct?
        public bool ProtocolDomainWildcard(string wildcardUrl) {
            WildcardUrl urlInAccount = new WildcardUrl("*://*.com");
            return urlInAccount.Matches(wildcardUrl);
        }

        [TestCase("http://google.com/login.php", Result = true)]
        [TestCase("http://google.fr/admin/login.php", Result = true)]
        [TestCase("http://intra.contractor/anything.php", Result = false)]
        public bool MultipleWildcards(string wildcardUrl) {
            WildcardUrl urlInAccount = new WildcardUrl("http://*.intra.google*/*login.php");
            return urlInAccount.Matches(wildcardUrl);
        }

        [TestCase("http://www.microsoft.com/login.php", Result = true)]
        [TestCase("http://yahoo.com/login.php", Result = true)]
        [TestCase("http://google.com/search.php", Result = false)]
        public bool ProtocolDomainPathWildcard(string wildcardUrl) {
            WildcardUrl urlInAccount = new WildcardUrl("*login.php");
            return urlInAccount.Matches(wildcardUrl);
        }
    }
}
